package net.mingsoft.examine.action.web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.mingsoft.base.entity.ResultData;
import net.mingsoft.basic.bean.EUListBean;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.basic.util.StringUtil;
import net.mingsoft.cms.biz.IContentBiz;
import net.mingsoft.examine.biz.ExamineBiz;
import net.mingsoft.examine.entity.ExamineEntity;
import net.mingsoft.examine.entity.QueryExamineVo;
import net.mingsoft.examine.enums.NoticeEnum;
import net.mingsoft.examine.utils.DateUtil;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author gengfa
 * @date 22/01/24
 */
@Api(value = "审批中心接口")
@Controller("WebCmsExamineAction")
@RequestMapping("/${ms.manager.path}/cms/examine")
public class ExamineAction {

    @Autowired
    private ExamineBiz examineBiz;

    @Autowired
    private IContentBiz contentBiz;

    @GetMapping("/my")
    public String my(HttpServletResponse response, HttpServletRequest request){
        return "/cms/examine/my";
    }

    @GetMapping("/list")
    public String list(HttpServletResponse response, HttpServletRequest request){
        return "/cms/examine/list";
    }

    @ApiOperation(value = "发布申请")
    @PostMapping("/fbsq")
    @ResponseBody
    public ResultData fbsq(@RequestBody ExamineEntity examineEntity){
        ResultData resultData=examineBiz.fbsq(examineEntity);
        return ResultData.build().success(resultData);
    }

    @ApiOperation(value = "我的申请/审批列表")
    @RequestMapping(value ="/getList",method = {RequestMethod.GET})
    @ResponseBody
    public ResultData getList(QueryExamineVo queryExamineVo, HttpServletResponse response, HttpServletRequest request, @ApiIgnore ModelMap model, BindingResult result) {
        BasicUtil.startPage();
        List<ExamineEntity> list = examineBiz.getList(queryExamineVo);
        return ResultData.build().success(new EUListBean(list,(int)BasicUtil.endPage(list).getTotal()));
    }

    @ApiOperation(value = "详情")
    @GetMapping("/get")
    @ResponseBody
    public ResultData get( String id, HttpServletResponse response, HttpServletRequest request, @ApiIgnore ModelMap model, BindingResult result){
        if(id==null) {
            return ResultData.build().error();
        }
        ExamineEntity examineEntity =examineBiz.getDetail(id);
        return ResultData.build().success(examineEntity);
    }

    @ApiOperation(value = "撤回/办理")
    @PostMapping("/updateExamine")
    @ResponseBody
    public ResultData updateExamine(@RequestBody ExamineEntity examineEntity, HttpServletResponse response, HttpServletRequest request, @ApiIgnore ModelMap model, BindingResult result){
        boolean b=examineBiz.updateExamine(examineEntity);
        return ResultData.build().success(b);
    }

    @ApiOperation(value = "详情（reportId）")
    @GetMapping("/getReportId")
    @ResponseBody
    public ResultData getReportId( String reportId, HttpServletResponse response, HttpServletRequest request, @ApiIgnore ModelMap model, BindingResult result){
        if(reportId==null) {
            return ResultData.build().error();
        }
        ExamineEntity examineEntity =examineBiz.getReportId(reportId);
        return ResultData.build().success(examineEntity);
    }
}
